package com.qjy.sqldemo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SQLiteDbHelper extends SQLiteOpenHelper {

    public static final String DB_NAME = "browser.db";
    public static final int VERSION = 1;
    public static final String BROWSER_ADDRESS = "Address";//地址栏数据库
    public static final String BROWSER_BOOKMARK = "Bookmark";//书签数据库
    public static final String BROWSER_HISTORY= "History";//历史数据库
    public static final String BROWSER_HOMEBOOK = "HomeBook";//主页导航栏数据库


    private static final String QJY_ADDRESS ="CREATE TABLE "+BROWSER_ADDRESS+
            "(addressId INTEGER  PRIMARY KEY AUTOINCREMENT," +
            "addressUrl TEXT NOT NULL" +
            ");";

    private static final String QJY_BOOKMARK ="CREATE TABLE "+BROWSER_BOOKMARK
            +"(bookmarkId INTEGER PRIMARY KEY AUTOINCREMENT," +
            "bookmarkTitle TEXT NOT NULL," +
            "bookmarkUrl TEXT NOT NULL," +
            "bookmarkTime TEXT NOT NULL);";

    private static final String QJY_HISTORY ="CREATE TABLE "+BROWSER_HISTORY
            +"(historyId INTEGER PRIMARY KEY AUTOINCREMENT," +
            "historyTitle TEXT NOT NULL," +
            "historyUrl TEXT NOT NULL);";

    private static final String QJY_HOMEBOOK ="CREATE TABLE "+BROWSER_HOMEBOOK
            +"(homeBookId INTEGER PRIMARY KEY AUTOINCREMENT," +
            "homeBookTitle TEXT NOT NULL," +
            "homeBookUrl TEXT NOT NULL," +
            "homeBookImage TEXT NOT NULL);";

    /**
     * 关联语句
     */
//    public static final String USER_MESSAGE="ALTER TABLE "+BEIDOU_MESSAGE+"ADD CONSTRAINT FromUserID FOREIGN KEY() REFERENCES references tb_user(id);";


    public SQLiteDbHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(QJY_ADDRESS);
        db.execSQL(QJY_BOOKMARK);
        db.execSQL(QJY_HISTORY);
        db.execSQL(QJY_HOMEBOOK);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // 数据库版本号变更会调用 onUpgrade 函数，在这根据版本号进行升级数据库
        switch (oldVersion) {
            case 1:
                // do something
                break;

            default:
                break;
        }
    }
}
